﻿'   FAHWatch7 RemoteClients class
'   Copyright (c) 2011 Marvin Westmaas ( MtM / Marvin_The_Martian )
'
'   This program is free software: you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation, either version 3 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program.  If not, see <http://www.gnu.org/licenses/>.
'
Imports System.Text
Public Class clsRemoteClients
    'Preliminary code, will use txt file for remote clients
    'Eventually use an xml config file, so yeah writealltext isn't 'clean' ect ect ect 
#Region "Form actions"
    Private _form As New frmRemoteClients
    Public ReadOnly Property IsFormActive As Boolean
        Get
            Return _form.Visible
        End Get
    End Property
    Public Sub ShowForm(Optional ByVal Owner As Form = Nothing)
        Try
            _form.FillForm()
            If Not IsNothing(Owner) Then
                _form.ShowDialog(Owner)
            Else
                _form.Show()
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
    Public Sub CloseForm()
        _form.CloseForm()
    End Sub
#End Region
#Region "External properties access"
    Public Sub Clear()
        Try
            Do While LogParser.Clients.Count > 1
                LogParser.RemoveClient(LogParser.Clients(1).ClientName)
            Loop
            sqData.SaveRemoteClients()
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
    Public Sub RemoveRemoteClient(ByVal Name As String)
        Try
            LogParser.RemoveClient(Name)
            sqData.SaveRemoteClients()
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
    Public Sub AddRemoteClient(ByVal Name As String, ByVal Location As String, FCPort As String, PWD As String, FWPort As String, Enabled As Boolean)
        Try
            LogParser.AddClient(Name, Location, FCPort, PWD, FWPort, Enabled)
            sqData.SaveRemoteClients()
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
    Public Sub SetState(ByVal Name As String, ByVal Enabled As Boolean)
        Try
            LogParser.SetClientState(Name, Enabled)
            sqData.SaveRemoteClients()
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
#End Region
End Class
